import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';

// 静态路由配置 - system-app 的所有页面路由（使用完整路径，避免与其他微应用冲突）
const routes: RouteRecordRaw[] = [
  // 根路由重定向
  {
    path: '/',
    redirect: '/system/user',
  },
  {
    path: '/system',
    component: () => import('@/layout/index.vue'),
    redirect: '/system/user',
    children: [
      {
        path: '/system/user',
        name: 'User',
        component: () => import('@/views/user/index.vue'),
        meta: {
          title: '用户管理',
        },
      },
      {
        path: '/system/user/profile',
        name: 'UserProfile',
        component: () => import('@/views/user/profile/index.vue'),
        meta: {
          title: '个人中心',
        },
      },
      {
        path: '/system/role',
        name: 'Role',
        component: () => import('@/views/role/index.vue'),
        meta: {
          title: '角色管理',
        },
      },
      {
        path: '/system/menu',
        name: 'Menu',
        component: () => import('@/views/menu/index.vue'),
        meta: {
          title: '菜单管理',
        },
      },
      {
        path: '/system/menus',
        name: 'Menus',
        component: () => import('@/views/menu/index.vue'),
        meta: {
          title: '菜单管理',
        },
      },
      {
        path: '/system/dept',
        name: 'Dept',
        component: () => import('@/views/dept/index.vue'),
        meta: {
          title: '部门管理',
        },
      },
      {
        path: '/system/post',
        name: 'Post',
        component: () => import('@/views/post/index.vue'),
        meta: {
          title: '岗位管理',
        },
      },
      {
        path: '/system/dict',
        name: 'Dict',
        component: () => import('@/views/dict/index.vue'),
        meta: {
          title: '字典管理',
        },
      },
      {
        path: '/system/dict/type/data/:dictId',
        name: 'DictData',
        component: () => import('@/views/dict/data.vue'),
        meta: {
          title: '字典数据',
        },
      },
      {
        path: '/system/config',
        name: 'Config',
        component: () => import('@/views/config/index.vue'),
        meta: {
          title: '参数设置',
        },
      },
      {
        path: '/system/notice',
        name: 'Notice',
        component: () => import('@/views/notice/index.vue'),
        meta: {
          title: '通知公告',
        },
      },
      // 骨架屏示例路由
      {
        path: '/system/examples/skeleton',
        name: 'SkeletonExamples',
        component: () => import('@/views/examples/SkeletonExamples.vue'),
        meta: {
          title: '骨架屏示例',
        },
      },
      // 翻页动画示例
      {
        path: '/system/examples/pagination',
        name: 'PaginationDemo',
        component: () => import('@/views/examples/PaginationDemo.vue'),
        meta: {
          title: '翻页动画示例',
        },
      },
      // DataTable Pro 演示
      {
        path: '/system/examples/datatable-pro',
        name: 'DataTablePro',
        component: () => import('@/views/examples/DataTablePro.vue'),
        meta: {
          title: 'DataTable Pro 演示',
        },
      },
      {
        path: '/system/user-skeleton',
        name: 'UserWithSkeleton',
        component: () => import('@/views/user/index-with-skeleton.vue'),
        meta: {
          title: '用户管理（带骨架屏）',
        },
      },
      // 示例页面（暂时禁用，因为这些示例使用了不存在的包和组件）
      // {
      //   path: '/system/examples/pro-table',
      //   name: 'ProTableDemo',
      //   component: () => import('@/views/examples/ProTableDemo.vue'),
      //   meta: {
      //     title: 'ProTable示例',
      //   },
      // },
      // {
      //   path: '/system/examples/pro-form',
      //   name: 'ProFormDemo',
      //   component: () => import('@/views/examples/ProFormDemo.vue'),
      //   meta: {
      //     title: 'ProForm示例',
      //   },
      // },
      // {
      //   path: '/system/examples/pro-upload',
      //   name: 'ProUploadDemo',
      //   component: () => import('@/views/examples/ProUploadDemo.vue'),
      //   meta: {
      //     title: 'ProUpload示例',
      //   },
      // },
      // {
      //   path: '/system/examples/datatable-loading',
      //   name: 'DataTableLoadingDemo',
      //   component: () => import('@/views/examples/DataTableWithLoadingDemo.vue'),
      //   meta: {
      //     title: 'DataTable加载遮罩示例',
      //   },
      // },
    ]
  },
];

// 创建路由实例（使用根路径，路由定义已包含完整路径）
const router = createRouter({
  history: createWebHistory('/'),
  routes,
  scrollBehavior(_to, _from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    }
    return { top: 0 };
  },
});

export default router;